package com.huixuebao.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * TODO
 *
 * @author yufatao
 * @version 1.0
 * @date 2020-11-01 20:15
 */
public class JsonUtil {

    public static final ObjectMapper objectMapper = new ObjectMapper();

    public static String getStringData(Object object) throws JsonProcessingException {
        return objectMapper.writeValueAsString(object);
    }

    public static <T> T getObjectData(String json, TypeReference<T> clazz) throws JsonProcessingException {
        return objectMapper.readValue(json, clazz);
    }

    public static <T> T getObjectData(String json, Class<T> clazz) throws JsonProcessingException {
        return objectMapper.readValue(json, clazz);
    }
}